﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.DescendanttransferCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.DescendanttransferCommandHandler
{
	/// <summary>
	/// 修改后裔转种
	/// </summary>
	/// <returns></returns>
	public class UpdateDescendanttransferCommandHandler : IRequestHandler<UpdateDescendanttransferCommand, int>
	{
		/// <summary>
		/// 接口
		/// </summary>
		private readonly IDescendantTransferService _descendantTransferService;
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="descendantTransferService"></param>

		public UpdateDescendanttransferCommandHandler(IDescendantTransferService descendantTransferService)
		{
			_descendantTransferService = descendantTransferService;
		}
		/// <summary>
		/// 修改后裔转种
		/// </summary>
		/// <returns></returns>
		public async Task<int> Handle(UpdateDescendanttransferCommand request, CancellationToken cancellationToken)
		{
			var entity = new Descendanttransfer()
			{
				CreateName = request.CreateName,
				CreateTime = request.CreateTime,
				CurrentBuilding = request.CurrentBuilding,
				CurrentField = request.CurrentField,
				DescendantDate = request.DescendantDate,
				DescendantId = request.DescendantId,
				DescendantSex = request.DescendantSex,
				EarTag = request.EarTag,
				IsDel = request.IsDel,
				ToBuildingManageId = request.ToBuildingManageId,
				ToColumMangementId = request.ToColumMangementId,
				UpdateName = request.UpdateName,
				UpdateTime = request.UpdateTime
			};
			var result = await _descendantTransferService.UpdateDescendanttransfer(entity);
			return result;
		}
	}
}
